package com.lwt.commom.vo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
//公共响应类
@Data
//无参
@NoArgsConstructor
//全参
@AllArgsConstructor
public class Result<T> {
    private Integer code;
    private String message;
    private T data;
    /**
     *  成功时候的调用           第一个<T>是固定语法 可以理解为在这个方法中使用的泛型用符号T表示，当然你也可以用别的名字。
     *  Result<T>代表类Result的定义中也是用了泛型public class Result<T> {}
     * */
    public static <T> Result<T> success(){
        return new Result<>(20000,"success",null);
    }
    public static <T> Result<T> success(T data){
        return new Result<>(20000,"success",data);
    }
    public static <T> Result<T> success(T data,String message){
        return new Result<>(20000,message,data);
    }
    public static <T> Result<T> success(String message){
        return new Result<>(20000,message,null);
    }
    public static<T>  Result<T> fail(){
        return new Result<>(20001,"fail",null);
    }
    public static<T>  Result<T> fail(Integer code){
        return new Result<>(code,"fail",null);
    }
    public static<T>  Result<T> fail(Integer code, String message){
        return new Result<>(code,message,null);
    }
    public static<T>  Result<T> fail( String message){
        return new Result<>(20001,message,null);
    }
}